package com.rpc.demo;

        import org.springframework.beans.BeansException;
        import org.springframework.context.ApplicationContext;
        import org.springframework.context.ApplicationContextAware;

        import java.util.Optional;

/**
 * @author yanzhuoleo
 * @version V1.0
 * @Description: spring context
 * @date 2018-01-25-上午11:50
 */

public class SpringContext implements ApplicationContextAware {


    private static ApplicationContext applicationContext;

    @Override
    public void setApplicationContext(ApplicationContext context) throws BeansException {
        applicationContext = context;
    }


    public static <T> T getBean(String beanName) {

        Object object = applicationContext.getBean(beanName);
        if(object != null) {
            return (T)object;
        }

        return null;
    }

}
